package com.snowleopard.findpeople.entity.account.nopersist;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MenuItem implements Comparable<MenuItem> {

    private String label;
    private String href;
    private String id;
    private Integer sequence;
    private Integer topMenuPos;

    private List<MenuItem> children = null;

    public MenuItem(final String label, final String href, final String id, final int sequence) {
        super();
        this.label = label;
        this.href = href;
        this.id = id;
        this.sequence = sequence;
    }

    public MenuItem(final String label, final String href, final String id, final int sequence,
            final int topMenuPos) {
        super();
        this.label = label;
        this.href = href;
        this.id = id;
        this.sequence = sequence;
        this.topMenuPos = topMenuPos;
    }

    public void putMenuItem(final MenuItem child) {
        if (children == null) {
            children = new ArrayList<MenuItem>();
        }

        children.add(child);
    }

    public List<MenuItem> getChildren() {
        Collections.sort(children);
        return children;
    }

    public boolean isLeaf() {
        return (children == null);
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(final String label) {
        this.label = label;
    }

    public String getHref() {
        return href;
    }

    public void setHref(final String href) {
        this.href = href;
    }

    public String getId() {
        return id;
    }

    public void setId(final String id) {
        this.id = id;
    }

    public Integer getTopMenuPos() {
        return topMenuPos;
    }

    public void setTopMenuPos(final Integer topMenuPos) {
        this.topMenuPos = topMenuPos;
    }

    @Override
    public int compareTo(final MenuItem next) {
        return this.sequence.compareTo(next.sequence);
    }

    @Override
    public boolean equals(final Object obj) {
        return super.equals(obj);
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }
}
